<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('波浪艇列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>编号：</label>
                            <input type="text" name="code"/>
                        </li>
                        <!--                        <li>-->
                        <!--                            <label for="deptId">所属机构：</label>-->
                        <!--                            <select id="deptId" name="deptId" class="form-control" style="display: inline">-->
                        <!--                                <option th:each="dept : ${deptList}" th:text="${dept.deptName}"-->
                        <!--                                        th:value="${dept.deptId}"></option>-->
                        <!--                            </select>-->
                        <!--                        </li>-->
                        <li>
                            <label for="bdMode">通信方式：</label>
                            <select id="bdMode" name="bdMode" th:with="type=${@dict.getType('sys_bd_mode')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>北斗卡号：</label>
                            <input type="text" name="card"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="boat:boat:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="boat:boat:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
<!--            <a class="btn btn-primary single disabled" onclick="uploadImg()" shiro:hasPermission="boat:boat:edit">-->
<!--                <i class="fa fa-edit"></i> 上传照片-->
<!--            </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="boat:boat:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="boat:boat:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-info single disabled" onclick="device()" shiro:hasPermission="boat:boat:device">
                <i class="fa fa-list-ul"></i> 分配设备
            </a>
            <a class="btn btn-info single disabled" onclick="cmd()" shiro:hasPermission="boat:boat:cmd">
                <i class="fa fa-send-o"></i> 指令发送
            </a>
            <!--            <a class="btn btn-info single disabled" onclick="alert()" shiro:hasPermission="boat:boat:alert">-->
            <!--                <i class="fa fa-exclamation-triangle"></i> 报警管理-->
            <!--            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var alertFlag = [[${@permission.hasPermi('boat:boat:alert')}]];
    var deviceFlag = [[${@permission.hasPermi('boat:boat:device')}]];
    var editFlag = [[${@permission.hasPermi('boat:boat:edit')}]];
    var removeFlag = [[${@permission.hasPermi('boat:boat:remove')}]];
    var cmdFlg = [[${@permission.hasPermi('boat:boat:cmd')}]];
    var bdModeDatas = [[${@dict.getType('sys_bd_mode')}]];
    var prefix = ctx + "boat/boat";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "波浪艇",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'code',
                    title: '编号'
                },
                {
                    field: 'model',
                    title: '型号'
                },
                {
                    field: 'card',
                    title: '北斗卡号'
                },
                {
                    field: 'imei',
                    title: '铱星卡号'
                },
                {
                    field: 'radius',
                    title: '跑偏半径',
                    formatter: function (value, row, index) {
                        if (!$.common.isEmpty(value)) value = value + '米';
                        return value;
                    }
                },
                {
                    field: 'lifeSpan',
                    title: '使用年限',
                    formatter: function (value, row, index) {
                        if (value !== null) value = value + '年';
                        return value;
                    }
                },
                {
                    field: 'dept.deptName',
                    title: '所属机构'
                },
                {
                    field: 'bdMode',
                    title: '通信模式',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(bdModeDatas, value);
                    }
                },
                {
                    field: 'maintainOrg',
                    title: '维护机构'
                },
                {
                    field: 'launchDate',
                    title: '下水日期'
                },
                {
                    field: 'rtsp',
                    title: '流媒体地址',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        var more = [];
                        // if (!alertFlag) more.push("<a class='btn btn-default btn-xs " + alertFlag + "' href='javascript:void(0)' onclick='alert(" + row.id + ")'><i class='fa fa-exclamation-triangle'></i>报警管理</a> ");
                        if (!editFlag) more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='uploadImg(" + row.id + ")'><i class='fa fa-cloud-upload'></i>上传照片</a> ");
                        if (!cmdFlg) more.push("<a class='btn btn-default btn-xs " + cmdFlg + "' href='javascript:void(0)' onclick='cmd(" + row.id + ")'><i class='fa fa-send-o'></i>指令发送</a> ");
                        if (!deviceFlag) more.push("<a class='btn btn-default btn-xs " + deviceFlag + "' href='javascript:void(0)' onclick='device(" + row.id + ")'><i class='fa fa-list-ul'></i>分配设备</a>");
                        if (more.length) actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多</a>');
                        return actions.join(' ');
                    }
                }]
        };
        $.table.init(options);
    });

    function getRow(id) {
        table.set();
        if ($.common.isEmpty(id)) {
            id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (id.length === 0) {
                $.modal.alertWarning("请选择一条记录");
                return null;
            }
        }
        let rows = $("#bootstrap-table").bootstrapTable('getData');
        return rows.find(r => r.id == id); // 这里必须2个等号 因为每一行的按钮 传入的id是字符串
    }

    /*设备分配*/
    function device(id) {
        var row = getRow(id);
        if (row) $.modal.open(`${row.name} ${row.code} 分配设备`, prefix + '/device/' + row.id, 620, 412);
    }

    function alert(id) {
        var row = getRow(id);
        if (row) $.modal.open(`${row.name} ${row.code} 告警管理`, prefix + '/alert/' + row.id);
    }

    function cmd(id) {
        var row = getRow(id);
        if (row) $.modal.openOptions({
            url: '/cmd/index/' + row.id,
            title: `${row.name} ${row.code} 指令发送`,
            width: 887,
            height: 742,
            btn: '确认',
            yes: function (index) {
                $.modal.close(index)
            }
        });
    }

    function uploadImg(id) {
        var row = getRow(id);
        $.modal.open(`${row.name} ${row.code} 上传照片`, '/boat/boat/upload/' + row.id, 800, 600)
    }

</script>
</body>
</html>